Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: wiggle and silhouette stacks #751

Merged
merged 30 commits into from
Jul 29, 2020

Conversation

markov00
Copy link
Member

@markov00 markov00 commented Jul 15, 2020

Summary

This PR adds the wiggle and silhouette stacks mode as available in vislib.
t is also to fix fit functions for stacked charts #450

Configuring a stackMode in a stacked area or bar chart will change the baseline offset used to render each group of stacks. StackMode are:

export const StackMode = Object.freeze({
  /** Applies a zero baseline and normalizes the values for each point such that the topline is always one. */
  Percentage: 'percentage' as const,
  /** Shifts the baseline so as to minimize the weighted wiggle of layers. */
  Wiggle: 'wiggle' as const,
  /** Shifts the baseline down such that the center of the streamgraph is always at zero. */
  Silhouette: 'silhouette' as const,
});

Applied to a stacked area chart it can be used to stream graphs
Screenshot 2020-07-27 at 09 39 52

close #715

Additional changes

Screenshot 2020-07-27 at 19 41 55

  • The PR also adjust how we fit the chart to the data domain: for zero-based charts (bar and area charts) the fit option doesn't have effects, thus the changes on the screenshots.

  • The PR finally adjust the clipped ranges for ordinal charts, where the lines where wrongly clipped due to a missing translate call when rendering.

  • Some tests are converted to functional tests, instead of unit tests.

BREAKING CHANGE:

  • PointStyleAccessor and BarStyleAccessor now calls the method with a DataSeriesDatum as first argument instead of a RawDataSeriesDatum
  • stackAsPercentage prop on BarsSpec and AreaSpec is replaced by stackMode that accept one StackMode.

Checklist

  • Any consumer-facing exports were added to src/index.ts (and stories only import from ../src except for test data & storybook)
  • Proper documentation or storybook story was added for features that require explanation or tutorials
  • Unit tests were updated or added to match the most common scenarios

markov00 added 5 commits July 15, 2020 12:28
formatNonStackedDataSeriesValues and formatStackedDataSeriesValues are always called with a false value of 'scaleToExtent'. Because of this, this commit removes that parameter from the call.
It also clean up and refactor some test into integration test
BREAKING CHANGE: PointStyleAccessor and BarStyleAccessor now calls the method with a DataSeriesDatum not with a RawDataSeriesDatum
@markov00 markov00 force-pushed the 2020_07_15-stack_mode branch from 545cdde to 6220e49 Compare July 22, 2020 15:49
@codecov-commenter
Copy link

codecov-commenter commented Jul 22, 2020

Codecov Report

Merging #751 into master will increase coverage by 0.21%.
The diff coverage is 85.36%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #751      +/-   ##
==========================================
+ Coverage   74.33%   74.54%   +0.21%     
==========================================
  Files         269      285      +16     
  Lines        9303     9578     +275     
  Branches     1936     1945       +9     
==========================================
+ Hits         6915     7140     +225     
- Misses       2383     2427      +44     
- Partials        5       11       +6     
Flag Coverage Δ
#unittests 74.01% <84.71%> (-0.32%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/chart_types/xy_chart/renderer/canvas/areas.ts 40.00% <0.00%> (ø)
..._types/xy_chart/renderer/canvas/primitives/path.ts 9.43% <0.00%> (-1.21%) ⬇️
src/chart_types/xy_chart/specs/bar_series.tsx 100.00% <ø> (ø)
src/components/tooltip/tooltip.tsx 70.00% <ø> (-0.33%) ⬇️
src/mocks/series/data.ts 100.00% <ø> (ø)
src/mocks/specs/specs.ts 77.01% <ø> (ø)
src/renderers/canvas/index.ts 44.00% <0.00%> (ø)
src/utils/geometry.ts 100.00% <ø> (ø)
...chart_types/xy_chart/utils/stacked_series_utils.ts 86.11% <85.29%> (-11.87%) ⬇️
src/chart_types/xy_chart/state/utils/utils.ts 92.57% <90.69%> (-1.20%) ⬇️
... and 30 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4455281...63b29a6. Read the comment docs.

markov00 added 4 commits July 22, 2020 18:01
the `stackMode` was introduced to apply percentage, wiggle and silhouette offset for stacking
charts.

BREAKING CHANGE: `stackAsPercentage` prop was replaced by `stackMode` that accept one `StackModes`.

fix elastic#715
@nickofthyme nickofthyme mentioned this pull request Jul 23, 2020
5 tasks
@markov00 markov00 added :data Data/series/scales related issue :specs Chart specifications related issue :xy Bar/Line/Area chart related enhancement New feature or request labels Jul 28, 2020
@markov00 markov00 marked this pull request as ready for review July 28, 2020 14:24
@markov00 markov00 requested a review from nickofthyme July 28, 2020 14:24
Copy link
Collaborator

@nickofthyme nickofthyme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes look good to me, still reviewing behavior and visual screenshot changes. This was lot fewer actual src code changes than I was expecting seeing the +6,975 −3,995.

After looking at the streamgraph example. I think we should change the tooltip highlighting behavior in a future PR. Maybe this is normal but to me having the geometry point at the top as the area is strange. I feel these chart types are more about the difference in relative height to where the top points are irrelevant. Maybe we just hide points altogether for streamgraphs charts and never highlight the tooltip values.

Screen Recording 2020-07-28 at 03 17 PM

src/chart_types/xy_chart/rendering/rendering.ts Outdated Show resolved Hide resolved
src/chart_types/xy_chart/rendering/rendering.ts Outdated Show resolved Hide resolved
src/chart_types/xy_chart/rendering/rendering.ts Outdated Show resolved Hide resolved
src/chart_types/xy_chart/rendering/rendering.ts Outdated Show resolved Hide resolved
src/utils/data/babynames.ts Outdated Show resolved Hide resolved
src/utils/domain.ts Show resolved Hide resolved
stories/area/14_stacked_band.tsx Show resolved Hide resolved
stories/area/16_test_stacked_with_missing.tsx Outdated Show resolved Hide resolved
stories/streamgraph/1_basic.tsx Outdated Show resolved Hide resolved
Copy link
Collaborator

@nickofthyme nickofthyme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice you changed the extra value appearance on many screenshots. I think we should try to keep sweeping visual changes like this to small PRs. That said, I verified all of the screenshots look ok with the changes, so I'm fine with those changes for this PR.

Some screenshots I couldn't see the difference. For instance the none type fitting function screenshots like integration/tests/__image_snapshots__/mixed-stories-test-ts-mixed-series-stories-fitting-functions-area-charts-end-value-set-to-2-should-display-correct-fit-for-type-none-1-snap.png as well as integration/tests/__image_snapshots__/all-test-ts-baseline-visual-tests-for-all-stories-legend-display-values-in-legend-elements-visually-looks-correct-1-snap.png. Are these just minor canvas rendering changes?

src/chart_types/xy_chart/state/utils/types.ts Show resolved Hide resolved
src/mocks/series/series.ts Show resolved Hide resolved
src/mocks/series/utils.ts Outdated Show resolved Hide resolved
src/mocks/series/utils.ts Outdated Show resolved Hide resolved
src/mocks/series/utils.ts Outdated Show resolved Hide resolved
src/chart_types/xy_chart/utils/fit_function.ts Outdated Show resolved Hide resolved
src/chart_types/xy_chart/utils/fit_function.ts Outdated Show resolved Hide resolved
src/chart_types/xy_chart/utils/fit_function.ts Outdated Show resolved Hide resolved
src/chart_types/xy_chart/utils/fit_function.ts Outdated Show resolved Hide resolved
src/chart_types/xy_chart/utils/fit_function.ts Outdated Show resolved Hide resolved
@markov00
Copy link
Member Author

@nickofthyme

Some screenshots I couldn't see the difference. For instance the none type fitting function screenshots like integration/tests/image_snapshots/mixed-stories-test-ts-mixed-series-stories-fitting-functions-area-charts-end-value-set-to-2-should-display-correct-fit-for-type-none-1-snap.png as well as integration/tests/image_snapshots/all-test-ts-baseline-visual-tests-for-all-stories-legend-display-values-in-legend-elements-visually-looks-correct-1-snap.png. Are these just minor canvas rendering changes?

Exactly, this probably is caused or by the changes to fix the dashed line misaligned, or due to smaller changes on the clipping ranges

I notice you changed the extra value appearance on many screenshots. I think we should try to keep sweeping visual changes like this to small PRs. That said, I verified all of the screenshots look ok with the changes, so I'm fine with those changes for this PR.

My bad I'm sorry for that, whenever something wrong caches my eyes I preferred to fix that as soon as possible to avoid forget it later... I will do better on my next PR

@nickofthyme
Copy link
Collaborator

My bad I'm sorry for that, whenever something wrong caches my eyes I preferred to fix that as soon as possible to avoid forget it later... I will do better on my next PR

No worries I feel the same way.

Copy link
Collaborator

@nickofthyme nickofthyme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Tested locally, with firefox and chrome. Tested fit function and banded stories.

Verified #766 and #450 are fixed

@markov00 markov00 merged commit 268fcc0 into elastic:master Jul 29, 2020
markov00 pushed a commit that referenced this pull request Aug 10, 2020
# [21.0.0](v20.0.2...v21.0.0) (2020-08-10)

### Bug Fixes

* update dep vulnerabilities, minimist and kind-of ([#763](#763)) ([4455281](4455281))
* **legend:** fix color anchor, add action context, fix action padding ([#774](#774)) ([4590a22](4590a22))
* **tooltip:** placement with left/top legends and single bars ([#771](#771)) ([e576b26](e576b26)), closes [#769](#769) [#770](#770)

### Features

* streamgraph and fit functions on stacked charts ([#751](#751)) ([268fcc0](268fcc0)), closes [#766](#766) [#715](#715) [#450](#450)

### BREAKING CHANGES

* the first parameter of `PointStyleAccessor` and `BarStyleAccessor` callbacks is changed from `RawDataSeriesDatum` to `DataSeriesDatum`. `stackAsPercentage` prop is replaced by `stackMode` that accept one `StackMode`.
@markov00
Copy link
Member Author

🎉 This PR is included in version 21.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@markov00 markov00 added the released Issue released publicly label Aug 10, 2020
@markov00 markov00 deleted the 2020_07_15-stack_mode branch November 25, 2020 11:48
AMoo-Miki pushed a commit to AMoo-Miki/OpenSearch-Dashboards that referenced this pull request Feb 10, 2022
# [21.0.0](elastic/elastic-charts@v20.0.2...v21.0.0) (2020-08-10)

### Bug Fixes

* update dep vulnerabilities, minimist and kind-of ([opensearch-project#763](elastic/elastic-charts#763)) ([843554f](elastic/elastic-charts@843554f))
* **legend:** fix color anchor, add action context, fix action padding ([opensearch-project#774](elastic/elastic-charts#774)) ([262f8d2](elastic/elastic-charts@262f8d2))
* **tooltip:** placement with left/top legends and single bars ([opensearch-project#771](elastic/elastic-charts#771)) ([75533b1](elastic/elastic-charts@75533b1)), closes [opensearch-project#769](elastic/elastic-charts#769) [opensearch-project#770](elastic/elastic-charts#770)

### Features

* streamgraph and fit functions on stacked charts ([opensearch-project#751](elastic/elastic-charts#751)) ([6f6a8cb](elastic/elastic-charts@6f6a8cb)), closes [opensearch-project#766](elastic/elastic-charts#766) [opensearch-project#715](elastic/elastic-charts#715) [opensearch-project#450](elastic/elastic-charts#450)

### BREAKING CHANGES

* the first parameter of `PointStyleAccessor` and `BarStyleAccessor` callbacks is changed from `RawDataSeriesDatum` to `DataSeriesDatum`. `stackAsPercentage` prop is replaced by `stackMode` that accept one `StackMode`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:data Data/series/scales related issue enhancement New feature or request released Issue released publicly :specs Chart specifications related issue :xy Bar/Line/Area chart related
Projects
None yet
3 participants